import requests
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def job_execute(job_args):
    print("进入 job_execute")
    print("传入的参数:", job_args)
    url = job_args.get("url", "https://gw.tcltech.com/ai/service-center/service/center/call")
    token = job_args.get("token", "2250483g1t1chs30341g1t1chse014d301a0284ba79c9bd201032b422a")
    app_id = job_args.get("appId", "1414991187919503360")

    Headers = {
        "Token": "2250483g1t1chs30341g1t1chse014d301a0284ba79c9bd201032b422a",
        "appId": "1414991187919503360",
        "Content-Type": "application/json"
    }

    print("URL:", url)
    print("Headers:", Headers)

    try:
        # response = requests.post(url, headers=Headers, timeout=60)  # 60秒超时
        response = requests.post(url, headers=Headers, timeout=60, verify=False)
        print("响应状态码:", response.status_code)
        print("响应内容:", response.text)
        response.raise_for_status()
    except requests.RequestException as e:
        return {"success": False, "message": f"请求失败: {e}"}

    try:
        result_json = response.json()
    except json.JSONDecodeError:
        return {"success": False, "message": "返回不是合法的JSON"}

    if result_json.get("code") != "0":
        return {"success": False, "message": "同步指标库失败!", "data": result_json}

    json_array = result_json.get("data", [])
    if not json_array:
        return {"success": True, "message": "无数据", "data": []}

    # 这里假设 BusIndicator 就是字典，可以封装成类
    list_data = json_array  

    return {"success": True, "message": "成功", "data": list_data}


job_args = {
    "url": "https://gw.tcltech.com/ai/service-center/service/center/call",
    "token": "2250483g1t1chse014d301a0284ba79c9bd201032b422a",
    "appId": "1414991187919503360"
}
result = job_execute(job_args)
print(result)